//===============================================================================
// Microsoft Architecture Strategy Team
// LitwareHR - SaaS Sample Application
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System;
using System.Collections.Generic;
using System.Text;
using LitwareHR.Recruiting.Contract;
using Shp.Runtime.Contract;
using System.ServiceModel;
using System.IdentityModel.Claims;

namespace LitwareHR.Recruiting.Services
{
    public class ProcessService : IProcessUC, IProcessSC
    {
        public Guid OpenRecruitingProcess(Position position)
        {
            Guid tenantId = Context.TenantId;
            if (tenantId == Guid.Empty)
                throw new System.Security.SecurityException();
            position.TenantId = tenantId;
            if (position.Id == Guid.Empty)
                throw new ArgumentNullException("position.Id");

            return ProcessLogic.OpenRecruitingProcess(position);
        }

        public List<Guid> GetOpenPositionList(Guid tenantId)
        {
            if (tenantId == Guid.Empty)
                throw new ArgumentNullException("tenantId");

            return ProcessLogic.GetOpenPositionList(tenantId);
        }

        public StringPair[][] GetRecruitingWorkflowListByApplicant(bool isOpen)
        {
            Guid tenantId = Context.TenantId;
            if (tenantId == Guid.Empty)
                throw new System.Security.SecurityException();
            string tmp = OperationContext.Current.IncomingMessageProperties[ClaimTypes.Name] as string;
            Upn upn = new Upn(tmp);

            return ProcessLogic.GetRecruitingWorkflowListByApplicant(tenantId, upn, isOpen);
        }

        public StringPair[][] GetRecruitingWorkflowList(bool isOpen)
        {
            Guid tenantId = Context.TenantId;
            if (tenantId == Guid.Empty)
                throw new System.Security.SecurityException();

            return ProcessLogic.GetRecruitingWorkflowList(tenantId, isOpen);
        }

        public void SubmitResume(Resume resume)
        {
            if (resume.PositionId == Guid.Empty)
                throw new ArgumentNullException("resume.PositionId");

            string tmp = OperationContext.Current.IncomingMessageProperties[ClaimTypes.Name] as string;
            Upn upn = new Upn(tmp);

            ProcessLogic.SubmitResume(resume, upn);
        }

        public void SubmitInterview(Interview interview)
        {
            if (interview.WorkflowId == Guid.Empty)
                throw new ArgumentNullException("interview.WorkflowId");

            string tmp = OperationContext.Current.IncomingMessageProperties[ClaimTypes.Name] as string;
            Upn upn = new Upn(tmp);

            ProcessLogic.SubmitInterview(interview, upn);
        }

        public void SubmitNegotiation(Negotiation negotiation)
        {
            if (negotiation.WorkflowId == Guid.Empty)
                throw new ArgumentNullException("negotiation.WorkflowId");

            string tmp = OperationContext.Current.IncomingMessageProperties[ClaimTypes.Name] as string;
            Upn upn = new Upn(tmp);

            ProcessLogic.SubmitNegotiation(negotiation, upn);
        }

        public void SubmitAcceptance(Acceptance acceptance)
        {
            if (acceptance.WorkflowId == Guid.Empty)
                throw new ArgumentNullException("acceptance.WorkflowId");

            string tmp = OperationContext.Current.IncomingMessageProperties[ClaimTypes.Name] as string;
            Upn upn = new Upn(tmp);

            ProcessLogic.SubmitAcceptance(acceptance, upn);
        }

        public void SubmitRejection(Rejection rejection)
        {
            if (rejection.WorkflowId == Guid.Empty)
                throw new ArgumentNullException("rejection.WorkflowId");

            string tmp = OperationContext.Current.IncomingMessageProperties[ClaimTypes.Name] as string;
            Upn upn = new Upn(tmp);

            ProcessLogic.SubmitRejection(rejection, upn);
        }
    }
}
